const jrdService = require('./service.js')

class JrdController {
  async getUserInfo(req, res, next) {
    try {
      const data = await jrdService.getUserInfo(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async getGroupList(req, res, next) {
    try {
      const data = await jrdService.getGroupList(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async createLoginQrcode(req, res, next) {
    try {
      const data = await jrdService.createLoginQrcode(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async checkScan(req, res, next) {
    try {
      const data = await jrdService.checkScan(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async quit(req, res, next) {
    try {
      await jrdService.quit(req.body)
      // 如果没有抛出错误，返回成功响应（虽然在这个例子中不会发生）
      res.status(200).json({
        code: 0,
        data: {},
        msg: ""
      })
    } catch (error) {
      // 检查是否是登录失效错误
      if (error.code === -1001) {
        res.status(200).json({
          code: -1001,
          data: {},
          msg: error.message
        })
      } else {
        next(error)
      }
    }
  }

  async getGoalConfig(req, res, next) {
    try {
      const data = await jrdService.getGoalConfig(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async searchAccountAuth(req, res, next) {
    try {
      const data = await jrdService.searchAccountAuth(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async searchWxdAccount(req, res, next) {
    try {
      const data = await jrdService.searchWxdAccount(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async getCrowdList(req, res, next) {
    try {
      const data = await jrdService.getCrowdList(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async getCrowdWxdList(req, res, next) {
    try {
      const data = await jrdService.getCrowdWxdList(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async getVideoList(req, res, next) {
    try {
      const data = await jrdService.getVideoList(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }

  async getWxdVideoList(req, res, next) {
    try {
      const data = await jrdService.getWxdVideoList(req.body)
      res.status(200).json({
        code: 0,
        data,
        msg: ""
      })
    } catch (error) {
      next(error)
    }
  }
}

module.exports = new JrdController()
